package com.xyhy.core.base.controller;

import java.util.List;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

public interface ICrudController<T, R, DR, ID> {
  @ApiOperation("获取指定ID的对象")
  @PostMapping(path = "/findById/{id}")
  @ApiImplicitParam(name = "id", paramType = "path", dataType = "string", value = "ID", required = true)
  default DR findById(@PathVariable ID id) {
    return null;
  }

  @ApiOperation("添加")
  @PostMapping(path = "/add")
  R add(@RequestBody T data) throws Exception;

  @ApiOperation("修改")
  @PostMapping(path = "/update")
  R update(@RequestBody T data) throws Exception;

  @ApiOperation("删除")
  @PostMapping(path = "/delete/{id}")
  @ApiImplicitParam(name = "id", paramType = "path", dataType = "string", value = "ID", required = true)
  ID delete(@PathVariable ID id) throws Exception;

  @ApiOperation("批量删除")
  @PostMapping(path = "/batch/delete")
  @ApiImplicitParam(name = "ids", paramType = "body", value = "ID数组", required = true, example = "[1, 2, 3]")
  List<ID> batchDelete(@RequestBody List<ID> ids);

}
